<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<script type="text/javascript">
    require([ "dojo/_base/array", "dojo/_base/xhr", "dojo/request", "dojo/topic", "dojo/json" , "dijit/form/Select"],
            function(array, xhr, request, topic, JSON, Select) {
                var deletItemsCount = 0;
                confsummaryRestForm = function(formId) {
                    dijit.byId(formId).reset();
                    if (formId.indexOf('UFD') != -1) {
                        var rowid = jQuery("#confsummaryGird").jqGrid('getGridParam', 'selrow');
                        var confsummary = jQuery("#confsummaryGird").jqGrid('getRowData', rowid);
                        dijit.byId('confsummaryUFD').setValues(confsummary);
                    }
                };
                topic.subscribe("confsummary/insertOrUpdate", confsummaryRestForm);
                var syncDB = function(url, jsonData) {
                    request.post(url, {
                        data : jsonData,
                        headers : {
                            'Content-Type' : "application/json; charset=utf-8"
                        },
                        timeout : 30000
                    }).then(function(response) {
                        topic.publish("notifyMsgTopic", {
                            message : response,
                            type : "message",
                            duration : 1000
                        });
                        var currentPage = jQuery('#confsummaryGird').jqGrid('getGridParam', 'page');
                        var pageSize = jQuery('#confsummaryGird').jqGrid('getGridParam', 'rowNum');
                        var totalCount = jQuery('#confsummaryGird').jqGrid('getGridParam', 'records') - deletItemsCount;
                        var totalPages = Math.ceil(totalCount / pageSize);
                        jQuery("#confsummaryGird").jqGrid('setGridParam', {
                            page : currentPage > totalPages ? totalPages : currentPage
                        }).trigger("reloadGrid");
                    }, function(error) {
                        alert(error);
                    });
                };
                confsummarySubmitForm = function(formId, type,status) {
                    var url = "confsummary/insert";
                    if (type == 'u') {
                        url = "confsummary/update";
                    }
                    var form = dijit.byId(formId);
                    var val={'status' : status};
                    form.setValues(val);
                    if (form.isValid()) {
                        var json = JSON.stringify(form.getValues());
                        syncDB(url, json);
                        form.hide();
                        topic.publish("confsummary/insertOrUpdate", formId);
                    } else {
                        form.validate();
                    }
                };
                confsummaryDelete = function() {
                    var ids = jQuery("#confsummaryGird").jqGrid('getGridParam', 'selarrrow') || [];
                    deletItemsCount = ids.length;
                    if (ids.length > 0) {
                        if (confirm('确认删除所选定的项？')) {
                            var confsummary = {};
                            confsummary.id = '';
                            array.forEach(ids, function(entry, i) {
                                confsummary.id += entry + ",";
                            });
                            syncDB("confsummary/delete", JSON.stringify(confsummary));
                        }
                    } else {
                        alert('请选择至少一条数据!');
                    }
                };
                confsummaryQuery = function(formId) {
                    var confsummary = dijit.byId(formId).getValues();
                    jQuery("#confsummaryGird").jqGrid('setGridParam', {
                        postData : confsummary,
                        mtype : "post"
                    }).trigger('reloadGrid');
                };
                confQuery = function(formId) {
                    var conf = dijit.byId(formId).getValues();
                    jQuery("#confQueryGird").jqGrid('setGridParam', {
                        postData : conf,
                        mtype : "post"
                    }).trigger('reloadGrid');
                };
                
                setValueToForm = function(formId){
                    var rowid = jQuery("#confQueryGird").jqGrid('getGridParam', 'selrow');
                    var conf = jQuery("#confQueryGird").jqGrid('getRowData', rowid);
                    //赋值到当前显示的dialog上面
                    if(dijit.byId("confsummaryIFD").open){
                        dijit.byId("confsummaryIFD").setValues(conf);
                    }
                    if(dijit.byId("confsummaryUFD").open){
                        dijit.byId("confsummaryUFD").setValues(conf);
                    }
                    dijit.byId("confQueryFD").hide();
                };
                
                //根据会议id来查询会议的详细内容
                selectbyId = function(date){
                    var postDate= {};
                    postDate.confid=date;
                    var jsondate =JSON.stringify(postDate);
                    request.post("conference/selectbyId", {
                          data : jsondate ,
                          headers : {
                              'Content-Type' : "application/json; charset=utf-8"
                          },
                          timeout : 30000
                      }).then(function(response) {
                         var is={
                             "0" : "否",
                             "1" : "是"
                         };
                         //不知道为什么要转两次才没有双引号
                         var res= JSON.parse(response);
                         res=JSON.parse(res);
                         res.isemail=is[res.isemail];
                         res.ismobile=is[res.ismobile];
                         dijit.byId('confInfoFD').setValues(res);
                         dijit.byId('confInfoFD').show();
                      }, function(error) {
                          alert(error);
                      });
                };
                
                //显示详情页面
                showSummyInfo = function (cl){
                   var date=jQuery("#confsummaryGird").jqGrid('getRowData', cl)
                   var url="confsummary/selectAttachment/"+date['sumid'];
                   request.post(url, {
                                 headers : {
                                     'Content-Type' : "application/json; charset=utf-8"
                                 },
                                 timeout : 30000
                             }).then(function(response) {
                                 var attachs = JSON.parse(response);
                                 var link='';
                                 
                                 array.forEach(attachs, function(entry, i) {
                                    link+="<a href='attachment/download?fileid="+entry.fileid+"' style='text-decoration: none;'/>"+entry.filename+"</a>&nbsp;&nbsp;"

                                 });
                                 dojo.byId("DattachmentArea").innerHTML=link;
                             }, function(error) {
                                 alert(error);
                             });
                   dijit.byId('summyInfoFD').setValues(date);
                   dijit.byId('summyInfoFD').show();
                };
                
                
                showconfInfo =function(confid){
                    var url="conference/selectAttachment/"+confid;
                    request.post(url, {
                        headers : {
                            'Content-Type' : "application/json; charset=utf-8"
                        },
                        timeout : 30000
                    }).then(function(response) {
                        var attachs = JSON.parse(response);
                        var attacharea = dojo.byId("SummaryConferenceAttachDetail");
                        var download = '';
                        array.forEach(attachs, function(entry, i) {
                            link="<a href='attachment/download?fileid="+entry.fileid+"' style='text-decoration: none;'/>"+entry.filename+"</a>&nbsp;&nbsp;"
                            download+=link;
                        });
                        attacharea.innerHTML=download;
                    }, function(error) {
                        alert(error);
                    });
                    selectbyId(confid);                                     
                };
                
                //为会议议题绑定数据
                request.post("conference/selectConfTopic", {
                    headers : {
                        'Content-Type' : "application/json; charset=utf-8"
                    },
                    timeout : 30000
                }).then(function(response) {
                    var ops=JSON.parse(response);
                    ops.push({label : "全部", value : "0", selected : "true"});
                    new Select({
                        name : "confid",
                        style: "width : 99%",
                        options: ops
                    }, "summarySelectconftopic").startup();
                }, function(error) {
                    alert(error);
                });
            });
</script>
<div data-dojo-type="dijit/Dialog" id="confsummaryIFD" title="新增">
  <div class="dijitDialogPaneContentArea">
    <input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="trim: true" type="hidden" name="status">
    <table>
      <tr>
        <td><label for="confid">会议名称: </label></td>
        <td>
            <input style="width: 99.5%" data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="required: true, trim:true, readOnly: true" type="text"
            name="conftopic" onclick="dijit.byId('confQueryFD').show()">
            <input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="required: true, trim:true, readOnly: true" type="hidden"
            name="confid">
        </td>
      </tr>
      <tr>
        <td><label for="sumcontent">纪要内容: </label></td>
        <td><div data-dojo-type="dijit/Editor" data-dojo-props="required: true, trim:true" type="text"
          name="sumcontent" /></td>
      </tr>
      <tr>
        <td><label for="sumcontent">附件: </label></td>
        <td>
            <input style="width: 99.5%" data-dojo-type="dijit/form/TextBox" data-dojo-props="trim:true" type="text" name="filename" onclick="uploadComponet(this,'Iconfsummaryfileid');" />
            <input data-dojo-type="dijit/form/TextBox" data-dojo-props="trim:true" type="hidden" name="fileid" id="Iconfsummaryfileid"/>
        </td>
      </tr>
    </table>
  </div>
  <div class="dijitDialogPaneActionBar">
    <button data-dojo-type="dijit/form/Button" type="button" onclick="confsummarySubmitForm('confsummaryIFD','i','1')">发送</button>
    <button data-dojo-type="dijit/form/Button" type="button" onclick="confsummarySubmitForm('confsummaryIFD','i','0')">保存</button>
    <button data-dojo-type="dijit/form/Button" type="button" onclick="confsummaryRestForm('confsummaryIFD');">重置</button>
  </div>
</div>
<div data-dojo-type="dijit/Dialog" id="confsummaryUFD" title="更新">
  <div class="dijitDialogPaneContentArea">
    <input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="required: true, readOnly: true" type="text"
      name="sumid" style="display: none;">
    <input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="trim: true" type="hidden" name="status">
    <table>
      <tr>
        <td><label for="confid">会议名称: </label></td>
        <td>
            <input style="width: 99.5%" data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="required: true, trim:true, readOnly: true" type="text"
            name="conftopic" onclick="dijit.byId('confQueryFD').show()">
            <input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="required: true, trim:true, readOnly: true" type="hidden"
            name="confid">
        </td>
      </tr>
      <tr>
          <td><label for="createtime">创建时间: </label></td>
          <td><input style="width: 99.5%" data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="trim: true, readOnly: true" type="text" name="createtime"></td>
      </tr>
      <tr>
          <td><label for="creator">创建者: </label></td>
          <td><input style="width: 99.5%" data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="trim: true, readOnly: true" type="text" name="creator"></td>
      </tr>
      <tr>
        <td><label for="sumcontent">纪要内容: </label></td>
        <td><div data-dojo-type="dijit/Editor" data-dojo-props="required: true, trim:true" type="text"
          name="sumcontent" /></td>          
      </tr>
      <tr>
        <td><label for="sumcontent">已有附件: </label></td>
        <td id="UattachmentArea">
        </td>
      </tr>
      <tr>
        <td><label for="sumcontent">附件: </label></td>
        <td>
            <input style="width: 99.5%" data-dojo-type="dijit/form/TextBox" data-dojo-props="trim:true" type="text" name="filename" id="Uconfsummaryfilename" onclick="uploadComponet(this,'Uconfsummaryfileid');" />
            <input data-dojo-type="dijit/form/TextBox" data-dojo-props="trim:true" type="hidden" name="fileid" id="Uconfsummaryfileid"/>
        </td>
      </tr>
    </table>
  </div>
  <div class="dijitDialogPaneActionBar">
    <button data-dojo-type="dijit/form/Button" type="button" onclick="confsummarySubmitForm('confsummaryUFD','u','1')">发送</button>
    <button data-dojo-type="dijit/form/Button" type="button" onclick="confsummarySubmitForm('confsummaryUFD','u','0')">保存</button>
    <button data-dojo-type="dijit/form/Button" type="button" onclick="confsummaryRestForm('confsummaryUFD');">重置</button>
  </div>
</div>

<div data-dojo-type="dijit/Dialog" id="confQueryFD" title="会议查询">
 <div class="dijitDialogPaneContentArea">
    <fieldset>
            <legend>&nbsp;&nbsp;信息选项&nbsp;&nbsp;</legend>
            <form id="queryConfForm" data-dojo-type="dijit/form/Form" method="post">
                <div style="margin-left: 5px;">
                   <table>
                       <tr>
                           <td><label for="confid">会议名称: </label></td>
                           <td><input data-dojo-type="dijit/form/TextBox" data-dojo-props="trim: true" type="text" name="conftopic"></td>
                           <td><button data-dojo-type="dijit/form/Button" label="查询" onclick="confQuery('queryConfForm')"/></td>
                       </tr>
                   </table>
                </div>
            </form>
    </fieldset>
    <div id="confgird">
          <table id="confQueryGird"></table>
          <div id="confQueryToolbar"></div>
    </div>
 </div>
 <div class="dijitDialogPaneActionBar">
        <button data-dojo-type="dijit/form/Button" onclick="setValueToForm()">确定</button>
 </div>
</div>

<div data-dojo-type="dijit/Dialog" id="summyInfoFD" title="纪要详情">
    <div class="dijitDialogPaneContentArea">
        <table>
          <tr>
            <td><label for="confid">会议名称: </label></td>
            <td>
                <input style="width: 80.5%" data-dojo-type="dijit/form/TextBox" data-dojo-props="required: true, trim:true, readOnly: true" type="text" name="conftopic" >
                <button style="text-align:right" data-dojo-type="dijit/form/Button" onclick="showconfInfo(dojo.byId('summyInfoconfid').value)">会议详情</button>
                <input style="width: 99.5%" data-dojo-type="dijit/form/TextBox" data-dojo-props="required: true, trim:true, readOnly: true" type="hidden" name="confid" id=summyInfoconfid>
            </td>
          </tr>
          <tr>
              <td><label for="createtime">创建时间: </label></td>
              <td><input style="width: 99.5%" data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="trim: true, readOnly: true" type="text" name="createtime"></td>
          </tr>
          <tr>
              <td><label for="creator">创建者: </label></td>
              <td><input style="width: 99.5%" data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="trim: true, readOnly: true" type="text" name="creator"></td>
          </tr>
          <tr>
            <td><label for="sumcontent">纪要内容: </label></td>
            <td><div data-dojo-type="dijit/Editor" data-dojo-props="required: true, trim:true, readOnly: true" type="text" name="sumcontent" /></td>          
          </tr>
          <tr>
            <td><label for="filename">附件: </label></td>
            <td id="DattachmentArea"></td>
          </tr>
        </table>
    </div>
    <div class="dijitDialogPaneActionBar">
    </div>
</div>

<div data-dojo-type="dijit/Dialog" id="confInfoFD" title="会议详情">
    <div class="dijitDialogPaneContentArea">
    <input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="required: true, readOnly: true" type="text" name="confid" style="display: none;">
    <table border="0">
        <tr>
            <td><label for="conftopic">会议议题: </label></td>
            <td colspan="3">
                <input style="width: 99.7%" data-dojo-type="dijit/form/TextBox" data-dojo-props="readOnly: true" name="conftopic"/>
            </td>
            <td><label for="roomname">会议室: </label></td>
            <td>
                <input data-dojo-type="dijit/form/TextBox" data-dojo-props="readOnly: true" name="roomname"/>
            </td>
        </tr>
        <tr>
            <td><label for="typename">会议类型: </label></td>
            <td colspan="3">
                <input style="width: 99.7%" data-dojo-type="dijit/form/TextBox" data-dojo-props="readOnly: true" name="typename"/>
            </td>
            <td><label for="feebudget">费用预算: </label></td>
            <td>
                <input data-dojo-type="dijit/form/TextBox" data-dojo-props="readOnly: true" name="feebudget"/>
            </td>
        </tr>
        <tr>
            <td><label for="ismobile">短信通知: </label></td>
            <td>
                <input data-dojo-type="dijit/form/TextBox" data-dojo-props="readOnly: true" name="ismobile"/>
            </td>
            <td><label for="isemail">邮件通知: </label></td>
            <td>
                <input data-dojo-type="dijit/form/TextBox" data-dojo-props="readOnly: true" name="isemail"/>
            </td>
            <td><label for="importlevel">重要级别: </label></td>
            <td>
                <input data-dojo-type="dijit/form/TextBox" data-dojo-props="readOnly: true" name="importlevel"/>
            </td>
        </tr>
        <tr>
            <td><label for="confcontent">会议内容: </label></td>
            <td colspan="5">
                <div data-dojo-type="dijit/Editor" data-dojo-props="plugins:[], height: 100" name="confcontent"/>
            </td>
        </tr>
        <tr>
            <td><label for="comperename">主持人: </label></td>
            <td>
                <input data-dojo-type="dijit/form/TextBox" data-dojo-props="readOnly: true" name="comperename"/>
            </td>
            <td><label for="recordername">记录人: </label></td>
            <td>
                <input data-dojo-type="dijit/form/TextBox" data-dojo-props="readOnly: true" name="recordername"/>
            </td>
            <td><label for="attendusersname">参加人: </label></td>
            <td>
                <input data-dojo-type="dijit/form/TextBox" data-dojo-props="readOnly: true" name="attendusersname"/>
            </td>
        </tr>
        <tr>
            <td><label for="starttime">开始时间: </label></td>
            <td>
                <input data-dojo-type="dijit/form/TextBox" data-dojo-props="readOnly: true" name="starttime"/>
            </td>
            <td><label for="endtime">结束时间: </label></td>
            <td>
                <input data-dojo-type="dijit/form/TextBox" data-dojo-props="readOnly: true" name="endtime"/>
            </td>
            <td><label for="checkname">审批人: </label></td>
            <td>
                <input data-dojo-type="dijit/form/TextBox" data-dojo-props="readOnly: true" name="checkname"/>
            </td>
        </tr>
        <tr>
            <td><label>附件: </label></td>
            <td colspan="5" id="SummaryConferenceAttachDetail">
            </td>
        </tr>
    </table>
  </div>
</div>
<fieldset>
  <legend>&nbsp;&nbsp;信息选项&nbsp;&nbsp;</legend>
  <form id="queryConfSummaryForm" data-dojo-type="dijit/form/Form" method="post">
    <div style="margin-left: 5px;">
      <table>
        <tr>
          <td><label for="confid">会议议题: </label></td>
          <td>
              <input id="summarySelectconftopic">
          </td>
        </tr>
        <tr>
          <td><label for="sumcontent">纪要内容: </label></td>
          <td><input data-dojo-type="dijit/form/TextBox" data-dojo-props="trim: true" type="text" name="sumcontent"></td>
        </tr>
      </table>
    </div>
  </form>
  <div style="padding: 5px;">
    <button id="confsummaryInsertBtn" data-dojo-type="dijit/form/Button" type="submit" label="新增">
      <script type="dojo/method" event="onClick" args="evt">
        dijit.byId('confsummaryIFD').show();
      </script>
    </button>
    <button id="confsummaryDeleteBtn" data-dojo-type="dijit/form/Button" type="button" label="删除" onclick="confsummaryDelete();"></button>
    <button id="confsummaryUpdateBtn" data-dojo-type="dijit/form/Button" type="button" label="更新">
      <script type="dojo/method" event="onClick" args="evt">
        var ids = jQuery("#confsummaryGird").jqGrid('getGridParam', 'selarrrow') || [];
        var confsummary = jQuery("#confsummaryGird").jqGrid('getRowData', ids[0]);  
        if (ids.length != 1) {
          alert('每次只能修改一条数据!');
        }else if(confsummary.status=="已发送"){
          alert('数据已发送不可更新请见谅!');
        }else{
        //用于查询附件
        require([ "dojo/_base/array","dojo/request","dojo/json"],
            function(array, request, JSON) {
          var url="confsummary/selectAttachment/"+confsummary['sumid'];
          request.post(url, {
                        headers : {
                            'Content-Type' : "application/json; charset=utf-8"
                        },
                        timeout : 30000
                    }).then(function(response) {
                        var attachs = JSON.parse(response);
                        var link='';
                        
                        array.forEach(attachs, function(entry, i) {
                           link+="<a href='attachment/download?fileid="+entry.fileid+"' style='text-decoration: none;'/>"+entry.filename+"</a>&nbsp;&nbsp;"

                        });
                        dojo.byId("UattachmentArea").innerHTML=link;
                        dijit.byId("Uconfsummaryfilename").setValue(filename.substring(0,filename.length-1));
                        dijit.byId("Uconfsummaryfileid").setValue(filename.substring(0,filename.length-1));
                    }, function(error) {
                        alert(error);
                    });
          });
          dijit.byId('confsummaryUFD').setValues(confsummary);
          dijit.byId('confsummaryUFD').show();
        };
      </script>
    </button>
    <button id="confsummaryQueryBtn" data-dojo-type="dijit/form/Button" type="button" label="查询"
      onclick="confsummaryQuery('queryConfSummaryForm');"></button>
  </div>
</fieldset>
<div id="gird">
  <table id="confsummaryGird"></table>
  <div id="confsummaryToolbar"></div>
</div>
<script type="text/javascript">
var status={
        1 : "已发送",
        0 : "未发送"
    };
    jQuery("#confsummaryGird").jqGrid({
        url : 'confsummary/queryAsList',
        datatype : "json",
        autowidth : true,
        rownumbers : true,
        height : 'auto',
        colNames : [
          '纪要ID',
          '会议ID',
          '会议名称',
          '创建时间',
          '创建者',
          '纪要内容',
          '状态',
          '详情'
        ],
        colModel : [ 
        {
          name : 'sumid',
          index : 'sumid',
          width : 60,
          key : true,
          hidden : true,
          align : 'center'
        },
        {
          name : 'confid',
          hidden : true,
          index : 'confid'
        },
        {
          name : 'conftopic',
          index : 'conftopic'
        },
        {
          name : 'createtime',
          index : 'createtime'
        },
        {
          name : 'creator',
          index : 'creator'
        },
        {
          name : 'sumcontent',
          index : 'sumcontent'
        },
        {
          name : 'status',
          index : 'status'
        },
        {
            name : 'info',
            index : 'info'
        }
        ],
        rowNum : 15,
        rowList : [ 15, 20, 25, 30 ],
        pager : '#confsummaryToolbar',
        // sortname : 'username',
        recordpos : 'right',
        viewrecords : true,
        sortorder : "desc",
        jsonReader : {
            repeatitems : false
        },
        gridComplete : function() {
            var ids = jQuery("#confsummaryGird").jqGrid('getDataIDs');
            for ( var i = 0; i < ids.length; i++) {
                var cl = ids[i];
                var carcheck = jQuery("#confsummaryGird").jqGrid('getRowData', cl);
                var mystatus=status[carcheck["status"]];
                var myinfo="<a href='javascript:' onclick='showSummyInfo("+'"'+cl+'"'+")'>详情</a>"; //alert("+'"'+carcheck.sumid+'"'+")
                jQuery("#confsummaryGird").jqGrid('setRowData', cl, {
                    status : mystatus,
                    info :myinfo
                });
            }
        },
        multiselect : true,
        shrinkToFit : false,
        caption : "会议纪要列表"
    });
    jQuery("#confsummaryGird").jqGrid('navGrid', '#confsummaryToolbar', {
        edit : false,
        add : false,
        del : false,
        search : false,
        refresh : true
    });
</script>
<script type="text/javascript">
    jQuery("#confQueryGird").jqGrid({
        url : 'conference/queryAsList/n',
        datatype : "json",
        width : 300,
        rownumbers : true,
        height : 'auto',
        colNames : [
          '会议ID',
          '会议名称'
        ],
        colModel : [ 
        {
          name : 'confid',
          index : 'confid',
          width : 60,
          key : true,
          hidden : true,
          align : 'center'
        },
        {
          name : 'conftopic',
          width : 200,
          index : 'conftopic'
        }
        ],
        rowNum : 15,
        rowList : [ 15, 20, 25, 30 ],
        pager : '#confQueryToolbar',
        // sortname : 'username',
        recordpos : 'right',
        viewrecords : true,
        sortorder : "desc",
        jsonReader : {
            repeatitems : false
        },
        multiselect : false,
        shrinkToFit : false,
        caption : "会议纪要列表"
    });
    jQuery("#confQueryGird").jqGrid('navGrid', '#confQueryToolbar', {
        edit : false,
        add : false,
        del : false,
        search : false,
        refresh : true
    });
</script>
